<template>
  <div>
    <div id="div3">
      <el-table
          :data="tableData1"
          border
          style="width: 81.7%">

        <el-table-column
            label="历史建议"
            prop="title"
            width="675">
        </el-table-column>
        <el-table-column
            label="操作"
            width="350">
          <template #default="scope">
            <el-button @click="checkadvicebyid(scope.row)">查看</el-button>
            <el-button @click="removeadvice(scope.row)">撤回</el-button>
          </template>
        </el-table-column>
      </el-table>


      <el-dialog v-model="orderInfo1" title="历史意见查看" :before-close="close1" >
        <template #footer>
          <div>
            <p >内容:{{tableData2.content}}</p>
            <p >回复:{{tableData2.reply}}</p>
          </div>
        </template>
<!--        <el-button @click="close1()" class="advice-b">关闭</el-button>-->
      </el-dialog>

    </div>
    <el-button type="primary" id="button1" @click="release()">新的建议</el-button>
    <el-dialog v-model="orderInfo2" title="新的意见" :before-close="close2" class="dialog1">
      <el-form-item label="意见名称">
        <el-input  v-model="title"></el-input>
      </el-form-item>
      <el-form-item label="意见内容">
        <el-input type="textarea"  v-model="content"></el-input>
      </el-form-item>
      <el-button type="primary" @click="advice">发布</el-button>
      <el-button @click="close2()">关闭</el-button>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";


export default {
  name: "OrderHistory",
  data(){
    
    return{
      input4:'5',
      input: '',
      input1: '',
      input2: '',
      tableData:[
      ],
      UserData:{
      },
      changeInfo: false,
      action: {},
      goods: {},
      user: {},
      orderInfo1:false,
      orderInfo2:false,
      tableData1: [],
      tableData2:  {
        title:'',
        reply:'',
        content:'',
      },
      title: '',
      content: '',
    }
  },

  methods:{
formatData(row, column, cellValue, index){
		
		//把传过来的日期进行回炉重造一下，又创建了一个js的 Date对象，进行重新构造，转为String字符串
		//最终返回 s 就可以了
		var s =	new Date(cellValue).toLocaleString();
	return s;
 },   
    publishsale(){
      request.get("http://localhost:8082/AfterSale/publishAfterSaleService?goodid="+this.UserData.goodsid+
      "&goodname="+this.UserData.goodsname+"&description="+this.UserData.description+"&").then(res => {
        if (res.flag)                    {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    showadvice(){
      request.get("http://localhost:8082/user/showadvice").then(res => {
        if (res.flag) {
          this.tableData1 = res.data;
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    removeadvice(row){
      this.id=row.id;
      request.get("http://localhost:8082/user/removeadvice?id="+this.id).then(res => {
        if (res.flag) {
          this.tableData2 = res.data;
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    checkadvicebyid(row){
      this.orderInfo1=true;
      this.id=row.id
      request.get("http://localhost:8082/user/checkadvicebyid?id="+this.id).then(res => {
        if (res.flag) {
          this.tableData2 = res.data;
          console.log('ghh',this.tableData2);
          this.$message({
            type: 'success',
            message: res.msg
          })
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    advice(){
      request.post("http://localhost:8082/user/advice?title="+this.title+"&content="+this.content).then(res =>{
        if (res.flag) {
          this.$message({
            type: 'success',
            message: res.msg
          })
        }
        else {
          this.$message.error(res.msg);
        }
      })
    },
    getOrders() {
      request.get("http://localhost:8082/order/viewOrders").then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg,  
          })
          console.log("this.tableData",this.tableData);
          console.log("this.tableData",this.tableData[0]['action']['id']);
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Showorder(data){
      this.action = data.action
      this.goods = data.goods
      this.readorder=true;
    },
    open() {
      this.changeInfo = true;
    },
    change(){
      this.changeInfo = false;
  },
    close1() {
      this.orderInfo1 = false;
    },
    close2() {
      this.orderInfo2 = false;
    },
    open1(row) {
      this.orderInfo1=true;
    },
    release(){
      this.orderInfo2=true;
    }
  },
  created() {
    this.getOrders()
    this.showadvice()
  }
}
</script>

<style scoped>
.div2{
  background-size: 100% ;
  float: left;
  margin-top: -200px;
}
.b3{
  margin-bottom: 20px;
}
.dialog1{
  z-index: 2;
}

</style>
